//
//  MessagePhotoMenuItem.m
//  Investment
//
//  Created by xujiuming on 14-12-7.
//  Copyright (c) 2014年 xujiuming. All rights reserved.
//

#import "MessagePhotoMenuItem.h"

@implementation MessagePhotoMenuItem
/*
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}*/
- (id)initWithFrame:(CGRect)frame withType:(NSString *)dataType
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //self.dataType=dataType;
    }
    return self;
}
-(void)setContentImage:(UIImage *)contentImage{
    //UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, self.frame.size.width - 10, self.frame.size.height - 20)];
    
    
    
    //UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, self.frame.size.width - 5, self.frame.size.height - 10)];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, self.frame.size.width - 5, self.frame.size.height - 10)];
    //imageView.backgroundColor = [UIColor orangeColor];
    imageView.image = contentImage;
    [self addSubview:imageView];
    
    UIButton *btnDelete = [UIButton buttonWithType:UIButtonTypeCustom];
    btnDelete.frame = CGRectMake(self.frame.size.width - 15, 0, 15, 15);
    //btnDelete.frame = imageView.frame;//CGRectMake(self.frame.size.width - 15, 0, 15, 15);
   // btnDelete.backgroundColor = [UIColor redColor];
    //[btnDelete setImage:[UIImage imageNamed:@"delete-circular.png"] forState:UIControlStateNormal];
    btnDelete.tag = self.index;
    [btnDelete addTarget:self
                  action:@selector(deletePhotoItem:)
        forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnDelete];
    
}
/*
    删除图片
 */
-(void)deletePhotoItem:(UIButton *)sender{
    
    ltag=sender.tag;
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否删除当前图片?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==0) {
        
    } else {
        if([self.delegate respondsToSelector:@selector(messagePhotoItemView:didSelectDeleteButtonAtIndex:)]){
            [self.delegate messagePhotoItemView:self
                   didSelectDeleteButtonAtIndex:ltag];//sender.tag
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
